

clear 
set scheme lean2, permanent
global pm = char(177)
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 

tab pweight


loc experiments "posterior unemp_prob z_unemp_cat unemp_county_prob z_profits infl_mean z_fin_prosp earn_mean earn_sd jobinsecurity z_ndcons_index_A z_stocktrade_f"

foreach var of varlist republican democrat finlit_index{
gen mis_`var' = `var'==.
replace `var'=0 if `var'==.
}

replace log_income=0 if inc_NR==1
global controls age agesq female log_income inc_NR atleast_bachelor midwest south west republican democrat finlit_index mis_republican mis_finlit_index

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""




foreach choice in `experiments' {


***OLS: weighted.


    qui reg `choice' treatment $controls [pw=pweight], r
    sigstar treatment, prec(3)
    estadd loc thisstat4 = "`r(bstar)'": col`colnum'
    estadd loc thisstat5 = "`r(sestar)'": col`colnum'
	*qui sum `choice'
    *estadd loc thisstat7 = r(N): col`colnum'

	
***OLS: unweighted.
	
    qui ivreg2 `choice'  treatment $controls, r first
	sigstar treatment, prec(3)
    estadd loc thisstat10 = "`r(bstar)'": col`colnum'
    estadd loc thisstat11 = "`r(sestar)'": col`colnum'
	qui sum `choice'  
    estadd loc thisstat13 = r(N): col`colnum'	
	
			
	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

}
	
loc rowlabels " " " "{\bf Panel A: Weighted results}" " " "High Recession" " " " " "\hline" "{\bf Panel B: Unweighted Results}" " " "High Recession" "  " " " "Observations" " " "Mean dep. var." "SD dep. var." "First stage F-stat" " "   "\hline" " "   "
loc rowstats ""

forval i = 1/13 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "weightnewtable.tex", replace cells(none) booktabs nonotes nomtitles /*nonum*/ compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
  mgroups("\shortstack{Posterior:\\Recession\\(percent)}"  "\shortstack{National\\unemployment\\(percent)}" "\shortstack{National\\unemployment\\(categorical)}" ///
  "\shortstack{County\\unemployment\\(percent)}"  "\shortstack{Firm\\profits\\(categorical)}" "\shortstack{\\Inflation:\\mean}" "\shortstack{Household\\financial\\prospects}" "\shortstack{Earnings\\growth:\\Mean}" ///
  "\shortstack{Earnings\\growth:\\Uncertainty}" "\shortstack{Personal\\unemployment\\(percent)}"  "\shortstack{Consumption\\growth\\(planned)}" "\shortstack{Stocks\\net purchases\\(scale)}", pattern(1 1 1 1 1 1 1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

	
	eststo clear	














